<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:ccts="urn:un:unece:uncefact:documentation:standard:CoreComponentsTechnicalSpecification:2"
	xmlns:xf="http://www.w3.org/2002/xforms"
	exclude-result-prefixes="xsd xsl"> 
	
	<xsl:import href="global-vars.xsl" />
	<xsl:import href="global-templates.xsl" />
	
	<xsl:output media-type="application/xhtml+xml" method="xml" 
		encoding="UTF-8" version="1.0" indent="yes" omit-xml-declaration="no"/>
	
	<xsl:template name="BinaryObjectTypeInstancePart">
		<xsl:param name="name" />
		<xsl:param name="prefix" />
		
		<xsl:choose>
			<xsl:when test="namespace-uri-for-prefix( $prefix, . ) != $global.ns.target">
				<xsl:element name="{$name}" namespace="{namespace-uri-for-prefix( $prefix, . )}">
					<xsl:attribute name="fileName" />
				</xsl:element>
			</xsl:when>
			<xsl:otherwise>
				<xsl:element name="{$name}" namespace="{$global.ns.target}">
					<xsl:attribute name="fileName" />
				</xsl:element>				
			</xsl:otherwise>
		</xsl:choose>		
	</xsl:template>
	
	<xsl:template name="BinaryObjectTypeBinding">
		<xsl:param name="bbie" />
		<xsl:param name="bbie.ref" />
		<xsl:param name="bbie.schema" />
		
		<xsl:variable name="attribute.info">
			<xsl:call-template name="GetAttributeInfo">
				<xsl:with-param name="type" select="substring-after( $bbie , ':' )"/>
				<xsl:with-param name="type.schema" select="$bbie.schema"/>
				<xsl:with-param name="type.attribute" select="'fileName'"/>
			</xsl:call-template>
		</xsl:variable>
		
		<xsl:element name="xf:bind">
			<xsl:attribute name="nodeset"><xsl:value-of select="$bbie.ref" />/@fileName</xsl:attribute>
			<xsl:attribute name="type"><xsl:value-of 
				select="$attribute.info/attribute/@type" /></xsl:attribute>
		</xsl:element>
	</xsl:template>
	
	<xsl:template name="BinaryObjectTypeElements">
		<xsl:param name="element.ref" required="yes" />
		<xsl:param name="element.den" required="yes" />
		<xsl:param name="businessterm" required="yes" />
		
		<xsl:element name="div">
			<xsl:attribute name="class" select="replace( replace( $element.den, ' ', '' ), '\.', '__' )"/>
			<xsl:element name="xf:label"><xsl:value-of select="$businessterm" /></xsl:element>
			<xsl:element name="xf:upload">
				<xsl:attribute name="ref"><xsl:value-of select="$element.ref" /></xsl:attribute>
				<xsl:element name="xf:filename">
					<xsl:attribute name="ref"><xsl:value-of select="$element.ref"/>/@fileName</xsl:attribute>
				</xsl:element>
			</xsl:element>
		</xsl:element>
	</xsl:template>
	
</xsl:stylesheet>